package cn.yunyichina.provider.base.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * Created by 15-AK on 2017/3/1.
 */
public class DruidUtil {
    private static DataSource dataSource;
    private static Properties pro;

    private DruidUtil(){}

    static {
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            InputStream inputStream =  loader.getResourceAsStream("conf/oldjdbc.properties");
            pro = new Properties();
            pro.load(inputStream);
            dataSource = DruidDataSourceFactory.createDataSource(pro);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static Connection getConnection(){
        try {
            return  dataSource.getConnection();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
